<template>
  <div>
    <div style="margin: 10px 0;">
      <el-button type="danger" icon="el-icon-delete" @click="delBatch">批量删除</el-button>
    </div>
    <el-table :data="tableData" @selection-change="handleSelectionChange" style="width: 100%"
              :header-cell-style="{background:'#e7e8ef',color:'#4f5257'}"
              stripe fixed border>
      <el-table-column
          prop="id"
          type="selection"
          width="40">
      </el-table-column>
      <el-table-column prop="temperature" label="体温" ></el-table-column>
      <el-table-column prop="symptom" label="是否含有发烧发热症状" ></el-table-column>
      <el-table-column prop="isCough" label="是否咳嗽" ></el-table-column>
      <el-table-column prop="healthCode" label="健康码颜色" ></el-table-column>
      <el-table-column prop="healthImg" label="健康码图片" width="130">
        <template slot-scope="scope">
          <el-image style="width: 100px; height: 100px" :src="scope.row.healthImg" :preview-src-list="[scope.row.healthImg]">
          </el-image>
        </template>
      </el-table-column>
      <el-table-column prop="addTime" label="打卡时间"></el-table-column>
      <el-table-column
          label="操作"
          width="100">
        <template slot-scope="scope">
          <el-popconfirm
              style="margin-left: 5px"
              confirm-button-text='确定'
              cancel-button-text='取消'
              icon="el-icon-info"
              icon-color="red"
              title="您确定删除吗？"
              @confirm="handleDelete(scope.$index, scope.row)">
            <el-button type="danger" size="mini" class="el-icon-remove-outline" slot="reference">删除</el-button>
          </el-popconfirm>
        </template>
      </el-table-column>
    </el-table>
    <div style="padding: 10px 0">
      <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="pageNum"
          :page-sizes="[5, 10, 15, 30]"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total">
      </el-pagination>
    </div>
  </div>
</template>

<script>
export default {
  name: "ReportDetail",
  data(){
    return{
      userId: this.$route.query.id,
      tableData:[],
      pageNum:0,
      pageSize:5,
      total:0,
    }
  },
  created() {
    this.load()
  },
  methods: {
    load(){
      this.request.get("/record/pageByUserId/"+this.userId,{
        params:{
          pageNum:this.pageNum,
          pageSize:this.pageSize,
        }
      }).then(res =>{
        this.tableData = res.data.records
        this.total=res.data.total
      })
    },
    handleClose(done) {
      this.$confirm('确认关闭？')
          .then(_ => {
            done();
          })
          .catch(_ => {});
    },
    handleDelete(index, row) {
      this.request.delete("/record/"+(index,row).id).then(res=>{
        if (res.code===200){
          this.load()
          this.$message({
            type: 'success',
            message: '删除成功!'
          });
        }
      })
    },
    delBatch(){
      let ids = this.multipleSelection.map(v =>v.id)
      if (ids.length!=0){
        this.$confirm('你正在进行批量删除操作, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.request.post("/record/del/batch/", ids).then(res => {
            if (res.code===200){
              this.load()
              this.$message({
                type: 'success',
                message: '批量删除成功!'
              });
            }else {
              this.$message({
                type: 'error',
                message: res.message
              });
            }
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        });
      }else {
        this.$message.warning("请选择删除记录")
      }
    },
    /**
     * 选择框
     * */
    handleSelectionChange(val) {
      this.multipleSelection = val;
      for (let i=1; i<=val; i++)
        console.log(this.multipleSelection[i])
    },
    /**
     * 自定义操作列
     * @param index
     * @param row
     */
    handleSizeChange(val) {
      this.pageSize = val;
      this.load()
    },
    handleCurrentChange(val) {
      this.pageNum=val
      this.load()
    },
    handleAvatarSuccess(res){
      this.form.img=res
    },
  }
}
</script>

<style scoped>

</style>